﻿using FrameworkCore.Extensions;
using FrameworkCore.Interfaces;
using Microsoft.AspNetCore.Http;

namespace Infrastructure.Services;

public class CurrentUserService : ICurrentUserService
{
    private readonly IHttpContextAccessor _httpContextAccessor;

    public CurrentUserService(
        IHttpContextAccessor httpContextAccessor
       )
    {
        _httpContextAccessor = httpContextAccessor;
    }
    public string? UserId => _httpContextAccessor.HttpContext?.User.GetUserId();
    public long? CurrentUserId
    {
        get
        {

            if (long.TryParse(UserId, out long id))
            {
                return id;
            }
            return null;
        }
    }
    public string? Email => _httpContextAccessor.HttpContext?.User.GetEmail();
    public string? UserName => _httpContextAccessor.HttpContext?.User.GetUsername();
    public string? DisplayName => _httpContextAccessor.HttpContext?.User.GetDisplayName();
}
